package com.dzx.design.creational.simplefactory;

/**
 * @author dzx
 * @ClassName:
 * @Description: 简单工厂模式
 * @date 2019年06月26日 16:25:58
 */
public class VideoFactory {
    public Video getVideo(String type) {
        if ("java".equals(type)) {
            return new JavaVideo();
        } else if ("python".equals(type)) {
            return new PythonVideo();
        } else {
            return null;
        }
    }

    public Video getVideoByReflect(Class c){
       Video video= null;
        try {
            video =(Video) Class.forName(c.getName()).newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return video;

    }
}
